#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/7/3 22:03
# @Author  : sailor233
# @File    : keyboard.py
# @Software: PyCharm
# @Des     :
import sys
from time import sleep

from selenium import webdriver
from selenium.webdriver import ActionChains, Keys
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://ceshiren.com/")
driver.implicitly_wait(5)
driver.find_element(By.ID,'search-button').click()
# 定位搜索的输入框
el_search_input = driver.find_element(By.ID,'search-term')
# 复制粘贴 win 和 mac 有所不同，因此区分下
cmd_ctrl = Keys.COMMAND if sys.platform == 'darwin' else Keys.CONTROL
# 在输入框 输入字符、全选剪切狗粘贴（PS：调用perform()后才会执行）
# 按下 ctrl建：key_down(cmd_ctrl,el_search_input)
# 全选、剪切、粘贴操作：send_keys('axvvvv')
# 释放ctrl键：key_up(cmd_ctrl,el_search_input)
ActionChains(driver).send_keys('chrome').\
    key_down(cmd_ctrl,el_search_input).\
    send_keys('axvvvv').\
    key_up(cmd_ctrl,el_search_input).perform()

sleep(10)